#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QSystemTrayIcon>
#include <Phonon/MediaObject>
#include <QStandardItemModel>
#include <QProcess>

#include "reminder.h"
#include "ui_mainwindow.h"

#include "interface.h"

class QMenu;
class QAction;

//class Logger;
class ReminderDialog;

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    bool hasMinimizedStartup();
    ~MainWindow();

public slots:
    void onOtherInstanceMessage(const QString &);
    void playSound(const QString& filename);
    void remind(Reminder* reminder);
    void saveReminder();
    void reminderState(Reminder* reminder);
    void applySettings();

protected:
    #ifdef Q_OS_WIN
    virtual bool winEvent(MSG *message, long *result);
    #endif
    void closeEvent(QCloseEvent *event);

private slots:
    void mute();
    void setSystemTrayIcon();
    void aboutMindReminder();
    void exitApplication();
    void addReminder();
    void multiplyReminder();
    void addReminder(const QDate& date);
    void editReminder();
    void deleteReminder();
    void deleteReminder(Reminder* r, bool ok = false);
    void systemTrayActivation(QSystemTrayIcon::ActivationReason reason);
    void toggleReminder();
    void loadRemindersList();
    void itemActivated(const QModelIndex& index);
    void itemEdit(const QModelIndex& index);
    void editSettings();
    void showTimeout();
    void testReminder();
    void executeLog(QProcess::ProcessState newState);
    void backupSettings();
    void clearReminderHistory(const int index);

    void on_actionOrientation_triggered();

private:
    void createTrayActions();
    void createMultimediaObject();
    void readSettings();
    void loadFromSettings();
    void saveSettings();
    void writeToSettings(Reminder* r);
    int maxIndex() const;
    bool hasMuted();
    void remind(Reminder* reminder, bool test);
    void writeLastCall(Reminder* r, bool nulldate = false);
    QDateTime getLastCall(Reminder* r) const;
    void checkMissedReminders();
    void checkMissedReminder(Reminder* r);


    bool loadUpdatePlugin();



    Ui::MainWindow *ui;
    ReminderDialog* dlg;
    //Logger* logger;
    typedef QMap<int, Reminder*> RemindersMap;
    QStandardItemModel* model;
    RemindersMap reminders;
    Reminder* current;
    Phonon::MediaObject* media;
    QSystemTrayIcon *trayIcon;
    QMenu *trayIconMenu;
    QAction *minimizeAction;
    QAction *maximizeAction;
    QAction *restoreAction;
    QAction *quitAction;
    QAction *muteAction;

    QTimer* timeout;

    UpdMgrInterface* updmgr;


};

#endif // MAINWINDOW_H
